<template>
	<view class="container">
		<uni-forms ref="form" :rules="{}">
			<uni-forms-item label="" name="">
				<uni-easyinput v-model="data.title" type="text" autoHeight placeholder="请输入评论标题" />
			</uni-forms-item>
			<uni-forms-item label="" name="">
				<uni-easyinput v-model="data.content" type="textarea" autoHeight placeholder="请输入评论内容" />
			</uni-forms-item>

			<uni-forms-item label="" name="">
				<button type="primary" @click="postComment">发表</button>
			</uni-forms-item>
		</uni-forms>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data: {
					"content": "",
					"date": "2024-11-12T013:23:33.121Z",
					"id": 0,
					"name": "",
					"title": ""
				}
			}
		},
		methods: {
			postComment() {
				// 设置发表日期
				this.data.date = new Date().toISOString().substring(0, 10)
				uni.request({
					url: 'http://localhost:8090/freshmenapp/message/addone',
					method: 'POST',
					data: this.data,
					success: res => {
						if (res.data.success) {
							uni.showToast({
								title: '成功',
								icon: 'none'
							});
						} else {
							uni.showToast({
								title: '失败',
								icon: 'none'
							});
						}
					},
					fail: () => {},
					complete: () => {}
				});
			}
		},
		onLoad(e) {
			// 获取待评价食物ID
			this.data.id = e.id || 1
			// 获取当前用户ID
			this.data.name = uni.getStorageSync('list').name
			uni.onTabBarMidButtonTap(function(e) {
				console.log(e)
			})
		}
	}
</script>

<style>

</style>